$(function() {
	
	$("#wetlandPlant_add_importantplant").click(function() {
		wetlandPlant_add_importantplant();
	});
	
	$("#wetlandPlant_add_alien").click(function() {
		wetlandPlant_add_alien();
	});
	
	$("#wetlandPlant_add_sub").click(function() {
		wetlandPlant_add_sub();
	});
	
});

var wetlandPlant_add_import_i = 2;
function wetlandPlant_add_importantplant(){
	var tr = $('<tr>'+
		'<td><input type="text" name="pro_cn_name_'+wetlandPlant_add_import_i+'"/></td>'+
		'<td><input type="text" name="pro_en_name_'+wetlandPlant_add_import_i+'"/></td>'+
		'<td><input type="text" name="pro_latin_name_'+wetlandPlant_add_import_i+'"/></td>'+
		'<td><input type="text" name="pro_IUCN_standard_'+wetlandPlant_add_import_i+'"/></td>'+
		'<td><input type="text" name="pro_CITES_standard_'+wetlandPlant_add_import_i+'"/></td>'+
		'<td><input type="text" name="pro_protection_level_'+wetlandPlant_add_import_i+'"/></td>'+
		'<td class="text-center">'+
			'<a class="green" style="cursor: pointer;" title="编辑">'+
					'<i class="ace-icon fa fa-pencil bigger-130"></i>'+
			'</a>　'+
			'<a class="red" style="cursor: pointer;" title="删除" onclick="wetlandPlant_del($(this))">'+
					'<i class="ace-icon fa fa-trash-o bigger-130"></i>'+
			'</a>'+
		'</td>'+
	'</tr>');
	$("#importantplant_tbody").append(tr);
	
	wetlandPlant_add_import_i ++;
	
}

var wetlandPlant_add_alien_i = 2;
function wetlandPlant_add_alien(){
	var tr = $('<tr>'+
		'<td><input type="text" name="ale_cn_name_'+wetlandPlant_add_alien_i+'"/></td>'+
		'<td><input type="text" name="ale_en_name_'+wetlandPlant_add_alien_i+'"/></td>'+
		'<td><input type="text" name="ale_latin_name_'+wetlandPlant_add_alien_i+'"/></td>'+
		'<td>'+
			'<input type="radio" value="无影响" name="ale_impact_'+wetlandPlant_add_alien_i+'">&nbsp;<span>无影响</span>&nbsp;&nbsp;'+
			'<input type="radio" value="潜在的" name="ale_impact_'+wetlandPlant_add_alien_i+'">&nbsp;<span>潜在的</span>&nbsp;&nbsp;'+
			'<input type="radio" value="轻微影响" name="ale_impact_'+wetlandPlant_add_alien_i+'">&nbsp;<span>实际存在（轻微影响）</span>&nbsp;&nbsp;'+
			'<input type="radio" value="主要影响" name="ale_impact_'+wetlandPlant_add_alien_i+'">&nbsp;<span>实际存在（主要影响）</span>'+
		'</td>'+
		'<td class="text-center">'+
			'<a class="green" style="cursor: pointer;" title="编辑">'+
					'<i class="ace-icon fa fa-pencil bigger-130"></i>'+
			'</a>　'+
			'<a class="red" style="cursor: pointer;" title="删除" onclick="wetlandPlant_del($(this))">'+
					'<i class="ace-icon fa fa-trash-o bigger-130"></i>'+
			'</a>'+
		'</td>'+
	'</tr>');
	$('#alienplant_tbody').append(tr);
	
	wetlandPlant_add_alien_i ++;
}

/**
 * 删除行
 * @param delBtn
 */
function wetlandPlant_del(delBtn){
	delBtn.parent().parent().remove();
}

/**
 * 提交信息
 */
function wetlandPlant_add_sub(){
	var option = {
			dataType : 'json',
			data : {wetlandParkId : wetlandParkId},
			success : function(value) {
				if (value == true) {
					wetlandPlant.html(wetlandPlant.text() + successHTML);
					$.gritter.add({
						title : '确认消息',
						text : '恭喜您,信息添加成功！',
						class_name : 'gritter-success'
					});
				} else {
					wetlandPlant.html(wetlandPlant.text() + warnHTML);
					$.gritter.add({
						title : '确认消息',
						text : '对不起,信息添加失败！',
						class_name : 'gritter-error'
					});
				}
			},
			error : function() {
				wetlandPlant.html(wetlandPlant.text() + warnHTML);
				$.gritter.add({
					title : '服务器错误',
					text : '对不起，服务器错误，请联系系统管理员！',
					class_name : 'gritter-error'
				});
			}
		};
		$("#wetlandPlant_form").ajaxForm(option).submit();
}

